home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / Explode2.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  2.6 KB  |  152 lines

  1. ' Explode
  2. ' Written by Scott Brosious
  3.  
  4. const width = 200, height = 200
  5. const nops = 2000         ' Number of pixels
  6. const Speed = 1           ' Speed   
  7.  
  8. dim xcntr,ycntr
  9.  
  10. xcntr = width / 2    
  11. ycntr = height / 2   
  12.  
  13. const scale = 8
  14.  
  15. dim buffer(width)(height)
  16.  
  17. dim col1#
  18. dim col2#
  19. dim texture
  20. dim a   
  21. dim i,j 
  22. dim time  ' Current time
  23. dim t1,t2 ' Starting and ending time variables
  24.  
  25. dim xpos(nops) ' Xposition
  26. dim ypos(nops) ' Yposition
  27. dim ang(nops)  ' Angles
  28. dim st(nops)   ' Start time
  29. dim et(nops)   ' End time
  30. dim mt(nops)   ' Time to move
  31.  
  32. for i = 1 to nops
  33.  
  34. gosub Inittime
  35.  
  36. st(i) = t1
  37. et(i) = t2
  38.  
  39. gosub Angles
  40.  
  41. ang(i) = a
  42.  
  43. next
  44.  
  45. ' Set 2D mode
  46. glMatrixMode (GL_PROJECTION)
  47. glLoadIdentity ()
  48. glOrtho (0, width, 0, height, -1, 1)
  49. glMatrixMode (GL_MODELVIEW)
  50. glDisable (GL_DEPTH_TEST)
  51.  
  52. texture = LoadTexture ("data\fb01.png")
  53.  
  54. glEnable (GL_TEXTURE_2D)    
  55.  
  56. ' Translucency, Blending
  57. glBlendFunc(GL_SRC_ALPHA,GL_ONE)
  58. glEnable(GL_BLEND)
  59.  
  60. while true    
  61.  
  62. ' Clear screen   
  63. glClear (GL_COLOR_BUFFER_BIT)   
  64.  
  65. glBindTexture (GL_TEXTURE_2D, texture)
  66.  
  67. for i = 1 to nops
  68.  
  69. if time > st(i) then mt(i) = mt(i) + 1 :endif ' If current time greater then start time then move it.
  70.  
  71. if mt(i) > et(i) then gosub Refresh :endif ' If movetime greater then endtime start again
  72.  
  73. xpos(i)= xcntr + cosd(ang(i)) * (mt(i) * Speed)
  74. ypos(i)= ycntr + sind(ang(i)) * (mt(i) * Speed)
  75.  
  76. if xpos(i) < 0 or xpos(i) > width then goto skip1 endif
  77. if ypos(i) < 0 or ypos(i) > height then goto skip1 endif
  78.  
  79. buffer(xpos(i))(ypos(i)) = buffer(xpos(i))(ypos(i)) + 1
  80.  
  81. skip1:       
  82.  
  83. next 
  84.  
  85. glBegin (GL_QUADS)
  86.  
  87. for j = 0 to height
  88. for i = 0 to width
  89.  
  90. col1# = buffer(i)(j)
  91.  
  92. if col1# = 0 then goto skip2 endif
  93. if col1# > 255 then col1# = 255 endif
  94.  
  95. col2# =  col1# / 255
  96.  
  97.       glColor4f (1, 1, 1, col2#)
  98.  
  99.       glTexCoord2f (0, 1)                         
  100.       glVertex2f (i - scale,j + scale)     ' Top left
  101.  
  102.       glTexCoord2f (0, 0)                         
  103.       glVertex2f (i - scale,j - scale)     ' Bottom left
  104.             
  105.       glTexCoord2f (1, 0)                         
  106.       glVertex2f (i + scale,j - scale)     ' Bottom right    
  107.  
  108.       glTexCoord2f (1, 1)                         
  109.       glVertex2f (i + scale,j + scale)     ' Top right
  110.  
  111. skip2:
  112.  
  113. next
  114. next
  115.  
  116. glEnd ()
  117.  
  118. ' Display output
  119. SwapBuffers ()
  120.  
  121. time = time + 1
  122.  
  123. wend
  124.  
  125. ReFresh:
  126.  
  127. gosub InitTime  
  128. st(i) = t1
  129. et(i) = t2
  130. mt(i) = 0
  131. gosub Angles
  132. ang(i) = a
  133.  
  134. return
  135.  
  136. InitTime:
  137.  
  138. t1 = rnd() % 100 
  139. t2 = rnd() % width
  140.  
  141. return              
  142.  
  143. Angles:
  144.  
  145. a = rnd() % 360
  146.  
  147. return
  148.  
  149.  
  150.  
  151.  
  152.